package old.test.util;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;

import old.model.Ship;

/**
 * Pannello che mostra la nave in 2D.
 * @author Jancarlos
 *
 */
public class ShipPanel extends JPanel implements Observer{
	
	private Ship userShip;
	private boolean isGuest;
	private final int WIDTH = 64;
	private final int WIDTH_MEZZI = WIDTH/2;
	
	/**
	 * Crea un pannello per visualizzare la ship del dell'utente principale.
	 * @param userShip ship dell'utente principale
	 */
	public ShipPanel( Ship userShip ) {
		super();
		userShip.addObserver(this);
		this.userShip = userShip;
		this.isGuest = false;
	}
	
	/**
	 * Crea un pannello per visualizzare una Ship.
	 * @param userShip ship dell'utente
	 * @param isGuest indicare se l'utente e' Guest
	 */
	public ShipPanel(Ship userShip, boolean isGuest ) {
		super();
		userShip.addObserver(this);
		this.userShip = userShip;
		this.isGuest = isGuest;
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		drawShip(g);
	}
	
	
	private void drawShip(Graphics g ){
		int xDraw = (int) userShip.getX()-WIDTH_MEZZI;
		int yDraw = (int) userShip.getY()-WIDTH_MEZZI;
		
		if(isGuest){
			g.setColor( new Color( 71, 158, 201, 128 ) );
		}else{
			g.setColor(Color.BLACK);
		}
		
		g.fillRect( xDraw, yDraw, WIDTH, WIDTH );
	}
	
	@Override
	public void update(Observable o, Object arg) {
		repaint();
	}

}
